package com.dlc.demo.daiqianma.presenter;

import com.dlc.demo.daiqianma.entity.UserEntity;
import com.dlc.demo.daiqianma.iview.ILoginView;
import com.dlc.demo.daiqianma.model.Callback;
import com.dlc.demo.daiqianma.model.UserModel;
import com.dlc.demo.daiqianma.util.SharedPreferencesHelper;

/**
 * 用户操作业务
 */
public class LoginPresenter extends  BasePresenter<ILoginView>{
    /**
     * 用户登录
     * @param userName
     * @param pwd
     */
    public void doLogin(String userName,String pwd){
        getView().showLoading();
        UserModel.doLogin(userName, pwd, new Callback<UserEntity>() {
            @Override
            public void onSuccess(UserEntity data) {
                //保存用户token信息到本地
                SharedPreferencesHelper.setToken(getView().getContext(),data.getToken());
                getView().loginSuccess();
            }

            @Override
            public void onFailure(String msg) {
                getView().showToast(msg);
            }

            @Override
            public void onError() {
                getView().showErr();
            }

            @Override
            public void onComplete() {
                getView().hideLoading();
            }
        });
    }
}
